package io.knifer.gokexceltask.pojo.domain;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.knifer.gokexceltask.excel.converter.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;

@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ExcelProperty(value = "编号", index = 9)
    private Long id;

    @ExcelProperty(value = "学号", index = 3)
    private String studentId;

    @ExcelProperty(value = "姓名", index = 8)
    private String name;

    @ExcelProperty(value = "身份证号", index = 4, converter = IdCardNumberEncryptConverter.class)
    private String idCardNumber;

    @ExcelProperty(value = "报道时间", index = 5)
    private LocalDateTime reportingAt;

    @ExcelProperty(value = "照片", index = 6)
    private String photoUrl;

    @Enumerated(EnumType.ORDINAL)
    @ExcelProperty(value = "状态", index = 7, converter = StudentStatusConverter.class)
    private Status status;

    @ManyToOne(optional = false)
    @JoinColumn(name = "faculties_id")
    @ExcelProperty(value = "学院", index = 0, converter = FacultiesConverter.class)
    private Faculties faculties;

    @ManyToOne(optional = false)
    @JoinColumn(name = "major_id")
    @ExcelProperty(value = "专业", index = 1, converter = MajorConverter.class)
    private Major major;

    @ManyToOne(optional = false)
    @JoinColumn(name = "classe_id")
    @ExcelProperty(value = "班级", index = 2, converter = ClasseConverter.class)
    private Classe classe;

    @OneToOne(optional = false, cascade = CascadeType.PERSIST)
    @JoinColumn(name = "user_id")
    @ExcelIgnore
    private User user;

    @CreatedDate
    @ExcelProperty(value = "创建时间", index = 10, converter = LocalDateTimeConverter.class)
    private LocalDateTime createAt;

    @LastModifiedDate
    @ExcelProperty(value = "修改时间", index = 11, converter = LocalDateTimeConverter.class)
    private LocalDateTime updateAt;

    @AllArgsConstructor
    @Getter
    public enum Status{
        FINE("在校"),
        DROPOUT("辍学"),
        UNKNOWN("未知");

        final String value;
    }
}
